package core.test.rest.database;

import core.framework.database.JPARepository;
import core.framework.database.Specification;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 * @author neo
 */
@Repository
public class JPATestEntityRepository extends JPARepository<JPATestEntity> {
    public JPATestEntity findByName(final String name) {
        return findOne(new Specification<JPATestEntity>() {
            @Override
            public void build(CriteriaQuery<JPATestEntity> query, Root<JPATestEntity> root, CriteriaBuilder builder) {
                query.where(builder.equal(root.get("name"), name));
            }
        });
    }
}
